﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DotNetCore.BannerManagement.BLL
{
    public class AdvertisementManager
    {

        /// <summary>
        /// Will get an advertisement based on its ID
        /// </summary>
        /// <param name="ID">The ID of the advertisement</param>
        /// <returns></returns>
        public Domain.dnc_Advertisement GetAdvertisementByID(int ID)
        {

            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            return repository.Getdnc_AdvertisementByID(ID);

        }

        /// <summary>
        /// Will get a list of advertisements for an advertiser
        /// </summary>
        /// <param name="advertiserID">The advertiser ID</param>
        /// <returns></returns>
        public List<Domain.dnc_Advertisement> GetAdvertisementByAdvertiserID(int advertiserID)
        {

            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            return repository.Getdnc_AdvertisementByAdvertiserID(advertiserID);

        }

        /// <summary>
        /// Will get the number of impressions for an advertisement
        /// </summary>
        /// <param name="advertisementID">The ID of the advertisement</param>
        /// <returns></returns>
        public Domain.Count GetImpressions(Int32 advertisementID)
        {
            DAL.Domain.CountRepositoryArtifacts.CountRepository repository = new DAL.Domain.CountRepositoryArtifacts.CountRepository();

            return repository.GetImpressionsByAdvertisementID(advertisementID);
        }

        /// <summary>
        /// Will get the number of click throughs received for an advertisement
        /// </summary>
        /// <param name="advertisementID">The ID of the advertisement</param>
        /// <returns></returns>
        public Domain.Count GetClickThroughs(Int32 advertisementID)
        {
            DAL.Domain.CountRepositoryArtifacts.CountRepository repository = new DAL.Domain.CountRepositoryArtifacts.CountRepository();

            return repository.GetClickThroughsByAdvertisementID(advertisementID);
        }
        
        /// <summary>
        /// Will provide the next advertisement to display.
        /// The logic for determining the next advertisement is
        /// based in the SQL
        /// </summary>
        /// <param name="zone"></param>
        /// <returns></returns>
        public Domain.dnc_Advertisement GetNextAdvertisement(String zone)
        {

            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            return repository.GetNextAdvertisement(zone);
        }

        /// <summary>
        /// Will insert an advertisement
        /// </summary>
        /// <param name="advertisement">The advertisement entity</param>
        public void InsertAdvertisement(Domain.dnc_Advertisement advertisement)
        {

            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            repository.Add(advertisement);

        }

        public List<Domain.dnc_Advertisement> GetAllAdvertisements()
        {

            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            return repository.GetAllFromdnc_Advertisement();

        }

        public List<Domain.dnc_Advertisement> GetAllPendingAdvertisements()
        {

            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            return repository.GetAllPendingFromdnc_Advertisement();

        }

        public List<Domain.dnc_Advertisement> GetAdvertisementsByUsername(int advertiserID)
        {

            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            return repository.Getdnc_AdvertisementByAdvertiserID(advertiserID);

        }

        /// <summary>
        /// Will insert an advertisement zone
        /// </summary>
        /// <param name="advertisementZone">The advertisement zone entity</param>
        public void InsertAdvertisementZone(Domain.dnc_AdvertisementZone advertisementZone)
        {

            DAL.Domain.dnc_AdvertisementZoneRepositoryArtifacts.dnc_AdvertisementZoneRepository repository = new DAL.Domain.dnc_AdvertisementZoneRepositoryArtifacts.dnc_AdvertisementZoneRepository();

            repository.Add(advertisementZone);

        }

        /// <summary>
        /// Will update an advertisement
        /// </summary>
        /// <param name="advertisement"></param>
        public void Update(Domain.dnc_Advertisement advertisement)
        {
            DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository repository = new DAL.Domain.dnc_AdvertisementRepositoryArtifacts.dnc_AdvertisementRepository();

            repository.Save(advertisement);

        }
    }
}
